#include "Mesh.h"
//---------------------------------------------------------------------------------------------//
Mesh::Mesh(Graphics &graphics) : Entity3D(graphics)
{
	m_pVertices = new D3DMeshVertex[8];

// 	m_pVertices[0].SetVertex(-50,-50,-50,0xff0000ff);
// 	m_pVertices[1].SetVertex(-50, 50,-50,0xff00ff00);
// 	m_pVertices[2].SetVertex( 50, 50,-50,0xffff0000);
// 
// 	m_pVertices[3].SetVertex( 50,-50,-50,0xff0000ff);
// 	m_pVertices[4].SetVertex(-50,-50, 50,0xffff0000);
// 	m_pVertices[5].SetVertex( 50,-50, 50,0xffffffff);
// 
// 	m_pVertices[6].SetVertex( 50, 50, 50,0xffffffff);
// 	m_pVertices[7].SetVertex(-50, 50, 50,0xffff0000);
// 
// 
// 
// 	USHORT indices[] = 
// 	{
// 	   0,1,2, 2,3,0, 4,5,6,
// 	   6,7,4, 0,3,5, 5,4,0,
// 	   3,2,6, 6,5,3, 2,1,7,
// 	   7,6,2, 1,0,4, 4,7,1
//     };

	//msdn.microsoft.com/en-us/library/bb205592(v=vs.85).aspx
	
	unsigned long color = 0xff00ff00;
	//m_pVertices[0].SetVertex( 1.0f, 1.0f,-1.0f,color,0.0f,0.0f,0.0f);
	//m_pVertices[1].SetVertex(-1.0f, 1.0f,-1.0f,color,0.0f,0.0f,0.0f);
	//m_pVertices[2].SetVertex(-1.0f, 1.0f, 1.0f,color,0.0f,0.0f,0.0f);
	//m_pVertices[3].SetVertex( 1.0f, 1.0f, 1.0f,color,0.0f,0.0f,0.0f);
	//m_pVertices[4].SetVertex( 1.0f,-1.0f,-1.0f,color,0.0f,0.0f,0.0f);
	//m_pVertices[5].SetVertex(-1.0f,-1.0f,-1.0f,color,0.0f,0.0f,0.0f);
	//m_pVertices[6].SetVertex(-1.0f,-1.0f, 1.0f,color,0.0f,0.0f,0.0f);
	//m_pVertices[7].SetVertex( 1.0f,-1.0f, 1.0f,color,0.0f,0.0f,0.0f);

	m_pVertices[0].SetVertex( 1.0f, 1.0f,-1.0f,color, 0.333333f, 0.666667f,-0.666667f);
	m_pVertices[1].SetVertex(-1.0f, 1.0f,-1.0f,color,-0.816497f, 0.408248f,-0.408248f);
	m_pVertices[2].SetVertex(-1.0f, 1.0f, 1.0f,color,-0.333333f, 0.666667f, 0.666667f);
	m_pVertices[3].SetVertex( 1.0f, 1.0f, 1.0f,color, 0.816497f, 0.408248f, 0.408248f);
	m_pVertices[4].SetVertex( 1.0f,-1.0f,-1.0f,color, 0.666667f,-0.666667f,-0.333333f);
	m_pVertices[5].SetVertex(-1.0f,-1.0f,-1.0f,color,-0.408248f,-0.408248f,-0.816497f);
	m_pVertices[6].SetVertex(-1.0f,-1.0f, 1.0f,color,-0.666667f,-0.666667f, 0.333333f);
	m_pVertices[7].SetVertex( 1.0f,-1.0f, 1.0f,color, 0.408248f,-0.408248f, 0.816497f);


	USHORT indices[] = 
	{
	   0,1,2, 0,2,3, 0,4,5,
	   0,5,1, 1,5,6, 1,6,2,
	   2,6,7, 2,7,3, 3,7,4,
	   3,4,0, 4,7,6, 4,6,5
	};

	m_pIndices = new USHORT[36];
	
	for (int i = 0; i < 36; i++)
	{
		m_pIndices[i] = indices[i];
	}

	m_rotation = 0;
}
//---------------------------------------------------------------------------------------------//
void Mesh::Draw(Graphics& g)
{
	m_rotation += 0.1f;

	g.SetTexture(NULL);
	g.SetMatrixMode(WORLD_MATRIX);
	g.LoadIdentity();
	//g.Translate(-300,0,0);
	//g.Scale(2,2);
	g.Rotate(-m_rotation,-m_rotation,0);	
	g.Scale(50,50,50);
	g.DrawElements(8, m_pVertices, 36, m_pIndices, 12, TRIANGLELIST );
	
// 	Start();
// 	Rotate(m_rotation,m_rotation,m_rotation);
// 	DrawElements(8, m_pVertices, 36, m_pIndices, 12, TRIANGLELIST);
}